<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input placeholder="名称" style="width: 200px;" class="filter-item" />
      <el-input placeholder="ip地址" style="width: 200px;" class="filter-item" />
      <el-input placeholder="序列号" style="width: 200px;" class="filter-item" />
    </div>

    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="ID" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="150px" label="设备SN" align="center">
        <template slot-scope="{row}">
          <span>{{ row.sn }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="100px" label="通道码" align="center">
        <template slot-scope="{row}">
          <span>{{ row.address }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="100px" label="网络地址" align="center">
        <template slot-scope="{row}">
          <span>{{ row.ip }}</span>
        </template>
      </el-table-column>

      <el-table-column width="180px" align="center" label="告警时间">
        <template slot-scope="scope">
          <span>{{ scope.row.created | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="告警类型">
        <template slot-scope="scope">
          <span>{{ scope.row.type }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="是否已读">
        <template slot-scope="scope">
          <span>{{ scope.row.hasRead }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="200px">
        <template>
            <el-button type="primary" size="small" icon="el-icon-check">
              标记已读
            </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

const list = [
  {id: 1, address: 'A0101', sn: 'BP20201501001', ip: '192.168.1.20', created: '2020-10-01 12:20:15', type: '电流过低', hasRead: '已读'},
  {id: 2, address: 'A0102', sn: 'BP20201501002', ip: '192.168.1.21', created: '2020-10-01 12:20:15', type: '电流过高', hasRead: ''},
  {id: 3, address: 'A0103', sn: 'BP20201501003', ip: '192.168.1.22', created: '2020-10-01 12:20:15', type: '电压过低', hasRead: '已读'},
  {id: 4, address: 'A0104', sn: 'BP20201501004', ip: '192.168.1.23', created: '2020-10-01 12:20:15', type: '电压过低', hasRead: '已读'},
  {id: 5, address: 'A0105', sn: 'BP20201501005', ip: '192.168.1.24', created: '2020-10-01 12:20:15', type: '电压过高', hasRead: ''}
]


export default {
  name: 'Alert',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.list = list;
      this.total = 144;
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
